home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).adf / PCQ / Examples / ChopCL.p next >
Text File  |  1989-03-31  |  3KB  |  82 lines

  1. external;
  2.  
  3. {
  4.     This procedure simply chops up the commandline into strings.
  5. These strings are actually just pointers into the array CommandLine,
  6. so you shouldn't mess with them, especially if you change their length.
  7. Use strcpy to copy them to your own storage.  Of course you can't use
  8. CommandLine until you've extracted what you want from these.  The
  9. maximum number of arguments you want should be placed in argc before
  10. the call.  After the call, argc will hold the actual number read.
  11.     This is designed to be compiled and assembled, then called
  12. using the external reference facility.  This has a benefit I'll talk
  13. about in a second.  The process goes like this:
  14.     1.  Compile this file using
  15.         Pascal ChopCL.p ChopCL.s
  16.  
  17.     2.  Assemble it using
  18.         A68k ChopCL.s ChopCL.o
  19.  
  20.     3.  In a program that can use this sort of program, include:
  21.  
  22.         type
  23.             argvtype = array [1..whatever] of string;
  24.  
  25.         procedure ChopCL(var a : argvtype; var m : Integer);
  26.             forward;
  27.  
  28.     4.  When you go to link your program, include ChopCL.o in
  29.         your list of object files.  For example if your file
  30.         is called prog.o, you would write:
  31.  
  32.         Blink prog.o chopcl.o small.lib to prog library pcq.lib
  33.  
  34.     5.  You're done.
  35.  
  36.     The benefit I mentioned earlier is that, in your own program,
  37. you can make any size array of arguments you need.  If your program
  38. only needs two arguments, make the array just two elements, then set
  39. argc to 2 before you send it.  Since there is no checking done between
  40. modules, you can simply use a forward declaration that works for you.
  41. This is known as cheating.
  42.     There is a program called ChopTest.p in this archive that
  43. will test this routine.
  44.  
  45. }
  46.  
  47. type
  48.     argvtype = array [0..100] of string;
  49.  
  50. procedure ChopCL(var argv : argvtype; var argc : Integer);
  51. var
  52.     clindex : Integer;
  53.     max  : Integer;
  54. begin
  55.     max := argc - 1;
  56.     argc := 0;
  57.     if max <= 0 then
  58.     return;
  59.     clindex := 1;
  60.     while (clindex < 128) and (argc <= max) do begin
  61.     while ((ord(commandline[clindex]) <= ord(' ')) or
  62.         (ord(commandline[clindex]) > ord(127))) and
  63.         (clindex < 128) do begin
  64.         if commandline[clindex] = chr(0) then
  65.         return;
  66.         clindex := succ(clindex);
  67.     end;
  68.     if clindex >= 128 then
  69.         return;
  70.     argv[argc] := string(adr(commandline[clindex]));
  71.     while (ord(commandline[clindex]) > ord(' ')) and
  72.         (ord(commandline[clindex]) < 127) and
  73.         (clindex < 128) do
  74.         clindex := succ(clindex);
  75.     argc := succ(argc);
  76.     if commandline[clindex] = chr(0) then
  77.         return;
  78.     commandline[clindex] := chr(0);
  79.     clindex := succ(clindex);
  80.     end;
  81. end;
  82.